<?php
namespace app\store\controller;
use think\Controller;

use app\common\common\model\oldModel\store\StoreManager;
use app\common\common\Server\commonServer;
use think\Request;

class Login extends Controller
{

    /**
     * 用户登陆
     * @author lgp
     * @datetime 2018/02/01 17:33
     * @version 1.0
     */
    public function index(){

        if (Request::instance()->isPost()) {
            $username = input('username');
            $password = input('password');
            $code = input('code');
            /*$openid = input('openid');
            $access_token = input('access_token');*/

            $userModel = new StoreManager();
            $map['username'] = $username;
            $map['password'] = md5( $password );
            $userInfo = $userModel->findByWhere( $map );
            if ( !$userInfo ){
                $this->error( '用户名或密码不正确');
            }
            //记录用户登录信息
            $store_user['id'] = $userInfo['id'];
            $store_user['username'] = $userInfo['username'];
            $store_user['name'] = $userInfo['name'];
            $store_user['store_id'] = $userInfo['store_id'];
            $store_user['last_login_time'] =time();
            session( 'store_user' , $store_user);

            $this->redirect( 'store/user/index' , array('code' => $code ) );
//            $this->success( '登录成功' ,  url('user/index' , array( 'code'=> $code)) );
        }
        return $this->view->fetch( );
    }


    /**
     * 失效二维码
     */
    public function qrcode(){
        return $this->view->fetch();
    }












}
